package com.cmc.cloud.cmclink.doc.enums.filter;

import cn.hutool.extra.spring.SpringUtil;
import com.cmc.cloud.cmclink.doc.api.document.emums.SpecialEnum;
import com.cmc.cloud.cmclink.doc.service.impl.special.DgCargoValidateServiceImpl;
import com.cmc.cloud.cmclink.doc.service.impl.special.FlexiCargoValidateServiceImpl;
import com.cmc.cloud.cmclink.doc.service.impl.special.OdoCargoValidateServiceImpl;
import com.cmc.cloud.cmclink.doc.service.impl.special.OogAkCargoValidateServiceImpl;
import com.cmc.cloud.cmclink.doc.service.special.SpecialCargoValidateService;
import lombok.Getter;

/**
 * @author 申天青
 * @date 2025/8/4
 * 特种货验证器枚举
 */
public enum SpecialValidatorEnum {

    /**
     * DG类型货物校验器
     */
    DG_VALIDATOR(SpecialEnum.DG, DgCargoValidateServiceImpl.class),

    /**
     * OOG类型货物校验器
     */
    OOG_VALIDATOR(SpecialEnum.OOG, OogAkCargoValidateServiceImpl.class),

    /**
     * AK类型货物校验器
     */
    AK_VALIDATOR(SpecialEnum.AK, OogAkCargoValidateServiceImpl.class),

    /**
     * ODO类型货物校验器
     */
    ODO_VALIDATOR(SpecialEnum.ODO, OdoCargoValidateServiceImpl.class),

    /**
     * FLEXI类型货物校验器
     */
    FLEXI_VALIDATOR(SpecialEnum.FLEXI, FlexiCargoValidateServiceImpl.class);

    ;
    /**
     * sepcialEnum
     */
    @Getter
    private SpecialEnum specialEnum;

    /**
     * 验证器类
     */
    @Getter
    private Class<? extends SpecialCargoValidateService> validatorClass;

    SpecialValidatorEnum(SpecialEnum specialEnum, Class<? extends SpecialCargoValidateService> validatorClass) {
        this.specialEnum = specialEnum;
        this.validatorClass = validatorClass;
    }
    /**
     * 获取校验器实例
     * @return 校验器实例
     */
    public SpecialCargoValidateService getValidatorInstance() {
        return SpringUtil.getBean(validatorClass);
    }
    /**
     * 根据货物类型获取对应的校验器枚举列表
     * @param specialEnum 货物类型
     * @return 校验器枚举
     */
    public static SpecialCargoValidateService getValidatorByType(SpecialEnum specialEnum) {
        for (SpecialValidatorEnum validatorEnum : values()) {
            if (validatorEnum.getSpecialEnum() == specialEnum) {
                return validatorEnum.getValidatorInstance();
            }
        }
        return null;
    }


}
